#include <iostream>

using namespace std;

void test_static_cast()
{
	int i = 10;
	double d = static_cast<double>(i) / 3; // it's similar with (double)i / 3;
}

void test_const(int &i)
{
	++i;
	cout<<"i = "<<i<<endl;
}

void test_const_cast()
{
	int i = 1;
	const int ci = 10;
	test_const(i); // i = 2
	test_const(const_cast<int&>(i)); // could; but no need to use it.
	test_const(const_cast<int&>(ci)); // could; but it's better don't do it.
	cout<<"ci = "<<ci<<endl; // i = 11;
}

class A
{
public:
	virtual void fun() {} // if no "virtual" method, can't use dynamic_cast
};
class B : public A {};

void test_dynamic_cast()
{
	A a;
	A *a1;
	B b;
	B *b1;

	a1 = &a;
	b1 = dynamic_cast<B*>(a1); // b1 = null;

	a1 = &b;
	b1 = dynamic_cast<B*>(a1); // b1 = &b;
}

void test_reinterpret_cast()
{
	cout<<"it's better not to use reinterpret_cast"<<endl;
}

int main()
{
	test_static_cast();

	test_const_cast();

	test_dynamic_cast();

	test_reinterpret_cast();

	return 0;
}
